package com.proj.springbootdemo;

import com.proj.springbootdemo.utils.ProjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;
import java.util.Properties;

/**
 * @author liujia
 */
@SpringBootApplication
public class SpringbootdemoApplication {

    private static Logger logger = LoggerFactory.getLogger(SpringbootdemoApplication.class);

    public static void main(String[] args) {

        // 检查base package配置
        String basePackage = null;
        Properties p = new Properties();
        try {
            p.load(SpringbootdemoApplication.class.getResourceAsStream("/application.properties"));
            basePackage = p.getProperty("project.basepackage");
        } catch (IOException e) {
            e.printStackTrace();
        }
        String basePackageFromUtils = ProjectUtils.basePackage();

        if (basePackageFromUtils.equals(basePackage)) {
            SpringApplication.run(SpringbootdemoApplication.class, args);
        } else {
            logger.error("请配置application.properties中的project.basepackage为正确的基础包名。");
            logger.error("property:" + basePackage + " --- util:" + basePackageFromUtils);
        }
    }
}
